# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=joomscan
pkgver=83.2ea8cc7
pkgrel=3
epoch=1
groups=('blackarch' 'blackarch-webapp')
pkgdesc='Detects file inclusion, sql injection, command execution vulnerabilities of a target Joomla! web site.'
url='http://joomscan.sourceforge.net/'
arch=('any')
depends=('perl-switch' 'perl-www-mechanize' 'perl-term-ansicolor')
makedepends=('git' 'dos2unix')
license=('GPL3')
source=("git+https://github.com/rezasp/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  dos2unix "$pkgname.pl"
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"

  install -Dm 755 "$pkgname.pl" "$pkgdir/usr/share/$pkgname/$pkgname.pl"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md CHANGELOG.md
  install -Dm 644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"

  rm *.md

  cp -a * "$pkgdir/usr/share/$pkgname/"

  # This is necessary to stop a warning from appearing.
  ln -s "/usr/share/doc/$pkgname" "$pkgdir/usr/share/$pkgname/doc"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec ./$pkgname.pl "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

